package com.mrlee.controller;

import com.github.pagehelper.PageInfo;
import com.mrlee.bean.Account;
import com.mrlee.bean.Service;
import com.mrlee.service.AccountService;
import com.mrlee.service.ServiceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/19.
 */
@Controller
public class BillController {

    @Resource
    private AccountService accountService;
    @Resource
    private ServiceService serviceService;

    /**
     * 跳转到bill_list
     * @return
     */
    @RequestMapping(value = "bill")
    public String tobill(){
        return "bill/bill_list";
    }

    /**
     * 跳转到bill_item
     * @return
     */
    @RequestMapping(value = "bitem")
    public String tobitem(){
        return "bill/bill_item";
    }

    /**
     * 跳转到bill_list
     * @return
     */
    @RequestMapping(value = "blist")
    public String toblist(){
        return "bill/bill_list";
    }

    /**
     * 跳转到bill_service_detail
     * @return
     */
    @RequestMapping(value = "/bdetail")
    public String todetail(){
        return "bill/bill_service_detail";
    }

    /**
     * 查询所有Account
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/allbill")
    public List<Account> allbill(){
        return accountService.selectallacc();
    }

    /**
     * bill分页
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "billpage")
    @ResponseBody
    public PageInfo<Account> adminByPage(@RequestParam(value = "pagenum",required = false)Integer pageNo,
                                         @RequestParam(value = "pagesize",required = false)Integer pageSize){
        return accountService.queryAccountByPageb(pageNo,3);
    }

    /**
     * 按id查Account
     * @param aid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "billbyid")
    public Account billById(@Param("aid")Integer aid){
        return accountService.selectbyid(aid);
    }

    /**
     * 按aid查Service
     * @param aid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/serbyaid")
    public List<Service> serbyaid(@Param("aid")Integer aid){
        return serviceService.selectbyaid(aid);
    }

    /**
     * 按id查service
     * @param sid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/serbysid")
    public Service serbysid(@Param("sid")Integer sid){
        return serviceService.selectByPrimaryKey(sid);
    }

}
